<?php

namespace App\Models\Common\TagData\Video;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Vcattag
 * @package App\Models\Common\TagData\Video
 * @version August 10, 2017, 1:21 am UTC
 */
class Vcattag extends Model
{
    use SoftDeletes;

    public $table = 'vcattags';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'vcat_id',
        'vcattag_no',
        'name',
        'title',
        'subtitle',
        'vcat_id',
        'created_at',
        'updated_at',
        'sp_id',
        'ogroup_id',
        'catid',
        'pid',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'vcat_id'    => 'integer',
        'vcattag_no' => 'string',
        'name'       => 'string',
        'title'      => 'string',
        'subtitle'   => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'vcattag_no' => 'max:100|unique:vcattags,vcattag_no,name:required|max:100',
        'title'      => 'max:100',
        'subtitle'   => 'max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\hasOne
     **/
    public function vcat()
    {
        return $this->hasOne(\App\Models\Common\CatData\Video\Vcat::class, 'id', 'vcat_id');
    }

    /**
     * 过滤发布数据
     **/
    public function scopeOnlinePublished($query, $status = 1)
    {
        return $query->where('publish_status', $status);
    }
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function sp()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Sp::class, 'id', 'sp_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function ogroup()
    {
        return $this->hasOne(\App\Models\Common\EntityData\Channel\Ogroup::class, 'id', 'ogroup_id');
    }
}
